package com.xiao.controller;

import com.xiao.domain.ResponseResult;
import com.xiao.domain.dto.TagListDto;
import com.xiao.domain.vo.BlogTagVo;
import com.xiao.service.BlogTagService;
import com.xiao.domain.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content/tag")
@Api(tags = "标签")
public class BlogTagController {

    @Autowired
    private BlogTagService blogTagService;

    @GetMapping("/list")
    @ApiOperation("返回所有标签列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "第几页"),
            @ApiImplicitParam(name = "pageSize",value = "页面大小"),
            @ApiImplicitParam(name = "tagListDto",value = "查询 DTO"),
    })
    public ResponseResult<PageVo> list(Integer pageNum, Integer pageSize, TagListDto tagListDto){
        ResponseResult<PageVo> responseResult = blogTagService.pageTagList(pageNum, pageSize, tagListDto);

        return responseResult;
    }

    @GetMapping("/listAllTag")
    @ApiOperation("获取所有的标签列表")
    public ResponseResult<BlogTagVo> listAllTag(){
        ResponseResult<BlogTagVo> responseResult = blogTagService.listAllTag();
        return  responseResult;
    }





    @DeleteMapping("/{id}")
    @ApiOperation("根据 id 列表 删除 标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "标签编号列表")
    })
    public ResponseResult deleteById(@PathVariable("id") List<Integer> ids){// 可省略 @PathVariable("id") 最好养成习惯都加上
        ResponseResult responseResult = blogTagService.deleteById(ids);
        return responseResult;
    }

    @GetMapping("/{id}")
    @ApiOperation("根据 id 查询标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "标签id")
    })
    public ResponseResult<BlogTagVo> queryById(@PathVariable("id") Integer id){
        ResponseResult<BlogTagVo> responseResult = blogTagService.queryById(id);
        return responseResult;
    }

    @PutMapping/*("/")*/
    @ApiOperation("保存修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "blogTagVo",value ="标签表VO" )
    })
    public ResponseResult saveUpdate(@RequestBody BlogTagVo blogTagVo){ // 声明为请求体
        ResponseResult responseResult = blogTagService.saveUpdate(blogTagVo);
        return responseResult;
    }

    @PostMapping/*("/")*/
    @ApiOperation("新增标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "blogTagVo",value = "标签表VO")
    })
    public ResponseResult addTag(@RequestBody BlogTagVo blogTagVo){

        ResponseResult responseResult = blogTagService.addTag(blogTagVo);

        return  responseResult;
    }



}